#include<iostream>
#include<time.h>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
inline double cpu_time() {
	return clock() * 1000 / CLOCKS_PER_SEC;
}
//图片旋转操作 img原始图，newIm旋转后的图，angle角度
void imrotate(Mat& img, Mat& newIm, double angle) {
	int len = max(img.cols, img.rows);
	Point2f pt(len/ 2., len/ 2.);
	Mat r = getRotationMatrix2D(pt, angle, 1.0);
	warpAffine(img, newIm, r, Size(len, len));
	
}
int main() {
	vector<String> fn;
	glob("G:\\peoplecountmateri\\*.png",fn,true);//遍历所有图片
	cout << fn.size() << endl;
	for (int i=0;i<fn.size();i++) 
	{
		cout << i << endl;
		Mat img = imread(fn[i]);
		//resize(img,img,Size(256,256));
		if (img.rows != 1280)
		{
			Rect rect1(123, 0, 768, 768);
			img =img(rect1);
			resize(img,img,Size(1280,1280));
		}
		Mat newIm,img1,img2,center;
		newIm = img.clone();

		//------指定3个矩形区域截图
		Rect r1 = Rect(480,50, 320,320);
		Rect r2 = Rect(480,130,320,320);
		Rect r3 = Rect(440,440,400,400);
		
		for (int j=0;j<12;j++)//每次旋转30度，所有循环12次
		{

			imrotate(newIm, newIm, 30);//旋转30度
			newIm(r1).copyTo(img1);//img1为r1区域的图
			newIm(r2).copyTo(img2);//img2为r2区域的图
			newIm(r3).copyTo(center);//center为r3区域的图
			
			char ab[100] = { 0 };
			sprintf_s(ab, "img%d-%d.jpg", i, j);
			string save_name = "G:\\image\\";
			save_name.append(ab);//保存图片的路径
			imwrite(save_name, img1);
			char ac[100] = { 0 };
			sprintf_s(ac, "1img%d-%d.jpg", i, j);
			string save_name1 = "G:\\image\\";
			save_name1.append(ac);
			imwrite(save_name1, img2);
			char ad[100] = { 0 };
			sprintf_s(ad, "2img%d-%d.jpg", i, j);
			string save_name2 = "G:\\center\\";
			save_name2.append(ad);
			imwrite(save_name2, center);

		}
	}
	return 0;
}